<?PHP	
	require 'config.php';
	require 'SimpleImage.php';
	
	$vID = $_GET['name'];
	$vRotation = $_GET['rotation'];
	$vOwner = $_GET['owner_type'];
	
	$vFileName = $vID . '.jpg';
	$vDestination = $imagesFolders[$vOwner] . $vFileName;	
	$vDestination_0 = $imagesFolders[$vOwner] . $imagesPrefixes[0] . $vFileName;
	file_put_contents($vDestination_0, $GLOBALS["HTTP_RAW_POST_DATA"]); 
	//Resize & rotate
	$image = new SimpleImage();
	$i = 0;
	foreach ($imagesPrefixes as $vPrefix)
	{
		$vDestination = $imagesFolders[$vOwner] . $vPrefix . $vFileName;
		$image->load($vDestination_0);
		if($i > 0)
			$image->smartResize($imagesSizes[$i]);
		else if ($i == 0)
			$image->rotate($vRotation);
		$image->save($vDestination, IMAGETYPE_JPEG);
		$image->destroyImage();
		$i++;
	}
	//Watermark
	$image->load($vDestination_0);
	$image->addWatermark($waterMark);
	$image->save($vDestination_0, IMAGETYPE_JPEG);
	$image->destroyImage();
	unset($image);
	echo '1';
?>